package pong.game.data;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class GameState {
	private ArrayList<WasherState> washers = new ArrayList<WasherState>();
	private ArrayList<HandlerState> handlers = new ArrayList<HandlerState>();
	private long time;
	
	public ArrayList<WasherState> getWashers() {
		return washers;
	}

	
	public ArrayList<HandlerState> getHandlers() {		
		return handlers;
	}


	void setTime(long time) {
		this.time = time;
	}


	long getTime() {
		return time;
	}
	
	private JSONArray getJSONwashers() {
		JSONArray ws = new JSONArray();
		for (WasherState w : washers) {
			ws.put(w.toJSON());
		}
		return ws;
	}
	
	private JSONArray getJSONhandlers() {
		JSONArray hs = new JSONArray();
		for (HandlerState h : handlers) {
			hs.put(h.toJSON());
		}
		return hs;
	}
	
	public JSONObject toJSON() {
		JSONObject json = new JSONObject();
		try {
			json.put("time", time);
			json.put("washers", getJSONwashers());
			json.put("handlers", getJSONhandlers());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return json;
	}
	
	public void parse(String data) {
		
	}
}
